package com.xinchuang.controller.targetSystem;

import com.alibaba.fastjson.JSONObject;
import com.xinchuang.common.Result;
import com.xinchuang.service.targetSystem.WeaponService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @ClassName WeaponController
 * @Description: TODO(写一段描述的话)
 * @Author zhangxuan
 * @Date 2022-03-03 15:14
 * @Verion V1.0
 */
@Api(value = "武器信息controller", tags = {"武器信息controller"})
@RestController
@RequestMapping(value = "/weapon")
public class WeaponController {

    @Resource
    private WeaponService weaponService;

    private final String WEAPON_DATA = "/data";

    private final String PUT_WEAPON_DATA = "/put";

    @ApiOperation(value = "新增武器库")
    @PostMapping(value = WEAPON_DATA)
    public Result addWeapon(
            @RequestBody JSONObject json) {
        String id = json.getString("id");
        String weaponName = json.getString("weaponName");
        String description = json.getString("description");
        return weaponService.addWeapon(id, weaponName, description);
    }

    @ApiOperation(value = "删除武器库")
    @DeleteMapping(value = WEAPON_DATA)
    public Result deleteWeapon(
            @RequestParam("id") String id
    ) {
        return weaponService.deleteWeapon(id);
    }

    @ApiOperation(value = "查询武器库")
    @GetMapping(value = WEAPON_DATA)
    public Result selectWeapon(
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize
    ) {
        return weaponService.selectWeaponList(pageNum, pageSize);
    }

    @ApiOperation(value = "查询武器库下拉列表")
    @GetMapping(value = PUT_WEAPON_DATA)
    public Result selectWeaponPut(
    ) {
        return weaponService.selectWeaponPut();
    }

}